package cn.edu.xmu.experiment.PulseComms.controller;


import cn.edu.xmu.experiment.PulseComms.Service.MessageService;
import cn.edu.xmu.experiment.PulseComms.entity.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @PostMapping("/private")
    public void sendPrivateMessage(@RequestBody Message message) {
        messageService.sendPrivateMessage(message);
    }

    @GetMapping("/{username}")
    public List<Message> getMessagesByUser(@PathVariable String username) {
        return messageService.getMessagesByUser(username);
    }

    // 获取群聊消息接口
    @GetMapping("/group/{groupName}")
    public List<Message> getGroupMessages(@PathVariable String groupName) {
        return messageService.getGroupMessages(groupName);
    }

}


